\documentclass[a4paper, 10pt]{article}
\usepackage[english]{babel}
\usepackage[final]{graphicx}
\usepackage{fontspec}
\usepackage{parskip}
\usepackage{xunicode}
\usepackage{xltxtra}
\setromanfont[Mapping=tex-text]{Ubuntu}
\fontspec{Ubuntu}

\begin{document}

\title{
	H04L2A Software for Real-time and Embedded Systems\\
	Prof. M. Lobelle\\
	Project 2: DHCP relay
}
\author{Andy Debrouwer, Sam Segers \& Mathias Spiessens}
\maketitle

\section{User guide}

The PIC development board will serve as a DHCP relay.
A DHCP relay is used in networks were no DHCP server is available.
The relay will act like a DHCP server to the local network, yet it just acts as a proxy for DHCP traffic.
Before deploying the DHCP relay it will need to be configured to comply with the local network.
The configuration is done by changing some configuration parameters (clearly marked in the source code) and recompiling the source code.
Among these configurations is the IP information for the relay.

\section{Specifications}

The relay agent will listen for broadcast messages containing a DHCP DISCOVER or DHCP REQUEST on the local network.
Once it receives such a message it will change the GIADDR field, increment the hops field in the DHCP packet and forward the modified message to a remote DHCP server using unicast.
When the server responds with a DHCP OFFER or DHCP NACK/ACK the relay agent will again increase the hops field and broadcast this message on the local network.
DHCP messages can have a maximum size of 576 bytes, this is the normal maximum for DHCP messages without any non-standard extensions.

\section{Developer documentation}

The low priority interrupt is used for the systick required by the TCP/IP stack.
This will enable the future developer to use the high priority interrupt.\\\\
The handling of a packet will be done by the Microchip TCP/IP stack until it reaches the application layer. 
The custom behaviour, for a DHCP relay, of this layer is specified by the application.\\\\
A custom linker script for use with sdcc/gputils is provided. The default script divides the data memory into banks, but the address spaces of these banks are consecutive.
The custom linker script will remove this unnecessairy division and provide a bigger continuous memory space.
The reason for doing this is the packet size of a DHCP packet.
The maximum packet size for a standard DHCP packet is 576 bytes, and the memory banks are 256 bytes.
Using the original division into banks of 256 bytes would require the programmer to use at least three different arrays to store just one packet.\\\\
To compile the DHCP relay application a few source files from the Microchip TCP/IP stack also need to be compiled.
Implementations of TCP/IP stack are usually not provided as libraries due to configuration and modification of the stack.\\\\
Two designs were made for the DHCP relay.
The first design doesn't allow for multiple DISCOVER-OFFER or REQUEST-ACK combinations at the same time, this design was chosen for the implementation.
The other design did allow multiple combinations simultaneously, this design would make the apllication less straightforward.\\\\
When using the DHCP relay behind a NAT (Network Address Translation) router some complications arise.
The DHCP protocol requires deep knowledge of the network it works on, but NAT routers seriously limit this requirement.
Two approaches for dealing with a NAT router have been considered.
The first problem is the IP address of the relay agent, the server shouldn't reply to the relay agent itself but to the NAT router it is behind.
But this introduces a new problem, the IP address of the NAT router is in a different range from the relay agent.
This causes the DHCP server to lease IP addresses in the wrong range and thus rendering the DHCP clients useless within their private network.
This second problem could be solved by a custom implementation/extension of the DHCP server.
Another solution would be to keep the server in the dark about the local network.
This would require extra behaviour in the relay agent, concretely the relay would need to modify the leased IP addresses before forwarding the packet to the client and requested IP addresses from the clients.
A few comments have been added to the source code to guide when doing this.

\begin{figure}[]
	\centering
	\includegraphics[angle=90,scale=.5]{current.png}
	\caption{First design.}
\end{figure}

\begin{figure}[]
	\centering
	\includegraphics[angle=90,scale=.5]{better.png}
	\caption{Second design.}
\end{figure}

\end{document}
